<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .login-box{
            width: 800px;
            height: 800px;
            margin: 50px auto;
            border: 1px solid gray;
        }
        .login-box .title{
            font-weight: 700;
            line-height: 100px;
            text-align: center;
        }
        .login-box .block{
            margin: 30px auto;
            text-align: center;
        }
        .login-box .block input{
            height: 60px;
            width: 60%;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 15px;
            outline: none;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div class="login-box">
        <div class="title">注册页</div>
        <div class="block">
            <input type="text" value="输入用户名">
        </div>
        <div class="block">
            <input type="password" value="输入密码">
        </div>
        <div class="block">
           <select name="" id="">
            <option value="男">男</option>
            <option value="女">女</option>
           </select>
        </div>
        <div class="block">
            <input type="text" value="年龄">
        </div>
        <div class="block">
            <input type="text" value="手机号">
        </div>
        <div class="block">
            <input type="button" value="注册">
        </div>
    </div>
</body>
</html>
<script src="./封装ajax.js"></script>
<script>
    //获取输入框
    var inputs =document.querySelectorAll('.login-box .block input')
    //获取select标签
    var select = document.querySelector('.login-box .block selector')
    //给button绑定点击事件
    inputs[4].onclick=function(){
if(inputs[0].value&&inputs[1].value){
if(/^\d{4}&/.test(inputs[1].value)){
    ajax('get','https://yantianfeng.com/api/register',{
        username:inputs[0].value,
        password:inputs[1].value,
        sex:select.value,
        age:inputs[2].value,
        phone:inputs[3].value
    },function(data){
            console.log(data);
        
    })
}else{
    alert('请输入正确的手机号')
}
}else{
    alert('用户名/密码不能为空')
}
    }
</script>